﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class web_Controls_ctrl_vl_left_home : System.Web.UI.UserControl
{
    Common _common = null;
    Common comm = new Common();
    DataTable dtt, dtt_center;
    Control ct;
    protected void Page_Load(object sender, EventArgs e)
    {
        _common = new Common();
        LoadVieclamNew();
        LoadVieclamNoibat();
        LoadUngvienNew();
        LoadUngvienNoibat();
        LoadGroupByChucdanh();
        LoadGroupByNganhnghe();
        //LoadNewsMain();
        //LoadNewsBHTN();
        dtt = comm.getDataTable("select id_page,title from CreatePages_page where notes is NOT NULL");
        if (dtt.Rows.Count > 0)
        {
            //this.Page.Title = dtt.Rows[0][1].ToString();
            //Lấy ra các thông tin của trang và danh sách các control tương ứng
            string sql_select = "SELECT B.*,C.* FROM dbo.CreatePages_page_block AS B" +
                " INNER JOIN dbo.CreatePages_block AS C ON B.id_block = C.id_block";
			string sql_order=" ORDER BY B.order_block";
            //Panel CENTER
            string sql_where = " WHERE id_page=" + dtt.Rows[0][0].ToString() + " and C.position='center'";
            dtt_center = comm.getDataTable(sql_select + sql_where+sql_order);
            
            string[] sTintuc;
            for (int i = 0; i < dtt_center.Rows.Count; i++)
            {
                if (!(String.IsNullOrEmpty(dtt_center.Rows[i]["path"].ToString())))
                {
                    if (dtt_center.Rows[i]["id_block"].ToString() == "17")
                    {
                        ct = Page.LoadControl(dtt_center.Rows[i]["path"].ToString());
                        ct.SkinID = dtt_center.Rows[i]["notes"].ToString();
                    }
                    else
                    {
                        sTintuc = dtt_center.Rows[i]["path"].ToString().Split('?'); 
                        if (sTintuc.Length > 1)
                        {
                            ct = Page.LoadControl(sTintuc[0].ToString());
                            ct.SkinID = sTintuc[1].ToString();
                        }
                        else
                        {
                            ct = Page.LoadControl(dtt_center.Rows[i]["path"].ToString());
                        }
                    }
                    panel_center.Controls.Add(ct);
                }
            }
        }
    }
    void LoadVieclamNew()
    {
        rpt_vieclam_new.DataSource = _common.ExeceuteDataset("select top 40 A.ma_ho_so, A.tieu_de_ho_so, A.so_luong_tuyen, B.ten_dia_chi from ViecLamTrong_ho_so_tuyen_dung as A left join DoanhNghiep_doanh_nghiep as C on A.ma_doanh_nghiep = C.ma_doanh_nghiep left join DanhMuc_dia_chi as B on A.noi_lam_viec = B.ma_dia_chi where A.kich_hoat = 1 and C.kich_hoat = 1 order by A.ngay_dang desc");
        rpt_vieclam_new.DataBind();
    }
    void LoadVieclamNoibat()
    {
        rpt_vieclam_noibat.DataSource = _common.ExeceuteDataset("select top 40 A.ma_ho_so, A.tieu_de_ho_so, A.so_luong_tuyen, B.ten_dia_chi from ViecLamTrong_ho_so_tuyen_dung as A left join DoanhNghiep_doanh_nghiep as C on A.ma_doanh_nghiep = C.ma_doanh_nghiep left join DanhMuc_dia_chi as B on A.noi_lam_viec = B.ma_dia_chi where A.kich_hoat = 1 and C.kich_hoat = 1 and C.hang_dau = 1 order by A.ngay_dang desc");
        rpt_vieclam_noibat.DataBind();
    }
    void LoadUngvienNew()
    {
        string _sql = "select top 40 A.ma_nguoi, A.ho_ten, convert(varchar, A.ngay_sinh, 103) ngaysinh_vn, C.ten_chuyen_mon from ConNguoi_nguoi as A left join (select top 1 * from ConNguoi_hoc_van_chuyen_mon where kich_hoat = 1) as B on A.ma_nguoi = B.ma_nguoi ";
        _sql += " left join danhmuc_chuyen_mon as C on B.ma_chuyen_mon = C.ma_chuyen_mon  ";
        _sql += " left join NguoiTimViec_ho_so as D on A.ma_nguoi = D.ma_nguoi where D.kich_hoat = 1 and A.kich_hoat = 1 order by D.ngay_dang_ky desc";

        rpt_ungvien_new.DataSource = _common.ExeceuteDataset(_sql);
        rpt_ungvien_new.DataBind();
    }
    void LoadUngvienNoibat()
    {
        string _sql = "select top 40 A.ma_nguoi, A.ho_ten, convert(varchar, A.ngay_sinh, 103) ngaysinh_vn, C.ten_chuyen_mon from ConNguoi_nguoi as A left join ConNguoi_hoc_van_chuyen_mon as B on A.ma_nguoi = B.ma_nguoi ";
        _sql += " left join danhmuc_chuyen_mon as C on B.ma_chuyen_mon = C.ma_chuyen_mon  ";
        _sql += " left join NguoiTimViec_ho_so as D on A.ma_nguoi = D.ma_nguoi where D.kich_hoat = 1 and A.kich_hoat = 1 and A.hang_dau = 1 order by D.ngay_dang_ky desc";

        rpt_ungvien_noibat.DataSource = _common.ExeceuteDataset(_sql);
        rpt_ungvien_noibat.DataBind();
    }
    void LoadGroupByChucdanh()
    {
        rpt_group_by_chucdanh.DataSource = _common.ExeceuteDataset("select A.ma_chuc_danh, A.ten_chuc_danh, B.total from danhmuc_chuc_danh as A right outer join (select ma_chuc_danh, count(ma_chuc_danh) as total from ViecLamTrong_ho_so_tuyen_dung where kich_hoat = 1 group by ma_chuc_danh) as B on A.ma_chuc_danh = B.ma_chuc_danh");
        rpt_group_by_chucdanh.DataBind();
    }
    void LoadGroupByNganhnghe()
    { 
        rpt_group_by_nganh.DataSource = _common.ExeceuteDataset("select A.ma_chuyen_mon, A.ten_chuyen_mon, B.total from DanhMuc_chuyen_mon as A right outer join (select count(A.ma_chuyen_mon) as total, A.ma_chuyen_mon from ViecLamTrong_yeu_cau_chuyen_mon as A where A.kich_hoat = 1 group by A.ma_chuyen_mon) as B on A.ma_chuyen_mon = B.ma_chuyen_mon");
        rpt_group_by_nganh.DataBind();
    }
}
